//
//  GetCommentVModel.m
//  HiCar
//
//  Created by huachun on 2019/4/15.
//  Copyright © 2019 丁一. All rights reserved.
//

#import "GetCommentVModel.h"
#import "HJonesNetting.h"
#import "CommentModel.h"
#import "HiJonesClass.h"
#import "SensitiveWordTools.h"

@implementation GetCommentVModel

- (instancetype)init:(id)responseObject{
    if (self = [super init]) {
        
        [HJonesNetting JonesNetting_POST:responseObject
                                  andURL:App_HOME_Comment_List
                              andtimeout:20.0
                                finished:^(NSError * _Nonnull error, NSDictionary * _Nonnull resultDict) {
                                    if (error) {
                                        [SVProgressHUD showErrorWithStatus:@"网络加载失败"];
                                        [self.delegate GetCommentSucces:0 array:nil page:0];
                                    }else{
                                        if ([[resultDict objectForKey:@"Code"] longLongValue]==1000) {

                                            NSMutableArray *hudonglist = [CommentModel mj_objectArrayWithKeyValuesArray:[resultDict objectForKey:@"CommentArray"]];

                                            [hudonglist enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                                                CommentModel *linmodel = (CommentModel *)obj;
                                                linmodel.comment = [[SensitiveWordTools sharedInstance]filter:linmodel.comment];
                                                linmodel.comment_height = [HiJonesClass getContent:linmodel.comment width:RECRWITCH-100 font:[UIFont systemFontOfSize:13] jianju:3]+5;
                                                if ([linmodel.to_comment_id intValue]>0) {
                                                    NSString *linstr;
                                                    if (linmodel.t_comment.length>0) {
                                                        linstr= [NSString stringWithFormat:@"%@: %@",linmodel.t_name,linmodel.t_comment];
                                                    }else{
                                                        linstr= [NSString stringWithFormat:@"作者已删除"];
                                                    }
                                                    linmodel.t_comment = [[SensitiveWordTools sharedInstance]filter:linstr];
                                                    linmodel.to_comment_height = [HiJonesClass getContent:linstr width:RECRWITCH-120 font:[UIFont systemFontOfSize:12] jianju:3]+20;
                                                }
                                            }];

                                            [self.delegate GetCommentSucces:1 array:hudonglist page:[[resultDict objectForKey:@"Page"] intValue]];
                                        }else{
                                            [SVProgressHUD showErrorWithStatus:[resultDict objectForKey:@"Message"]];
                                            [self.delegate GetCommentSucces:0 array:nil page:0];
                                        }
                                    }
                                }
                              passmanger:^(NSURLSessionDataTask * _Nonnull manger) {

                              }
                             andprogress:^(NSProgress * _Nonnull CProgress) {

                             }];
        
    }
    return self;
}

@end
